home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / target.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-22  |  14.8 KB  |  420 lines

  1. /* Interface between GDB and target environments, including files and processes
  2.    Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.  Written by John Gilmore.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #if !defined (TARGET_H)
  22. #define TARGET_H
  23.  
  24. /* This include file defines the interface between the main part
  25.    of the debugger, and the part which is target-specific, or
  26.    specific to the communications interface between us and the
  27.    target.
  28.  
  29.    A TARGET is an interface between the debugger and a particular 
  30.    kind of file or process.  Targets can be STACKED in STRATA, 
  31.    so that more than one target can potentially respond to a request.
  32.    In particular, memory accesses will walk down the stack of targets
  33.    until they find a target that is interested in handling that particular
  34.    address.  STRATA are artificial boundaries on the stack, within
  35.    which particular kinds of targets live.  Strata exist so that
  36.    people don't get confused by pushing e.g. a process target and then
  37.    a file target, and wondering why they can't see the current values
  38.    of variables any more (the file target is handling them and they
  39.    never get to the process target).  So when you push a file target,
  40.    it goes into the file stratum, which is always below the process
  41.    stratum.  */
  42.  
  43. #include "bfd.h"
  44.  
  45. enum strata {
  46.     dummy_stratum,        /* The lowest of the low */
  47.     file_stratum,        /* Executable files, etc */
  48.     core_stratum,        /* Core dump files */
  49.     process_stratum        /* Executing processes */
  50. };
  51.  
  52. struct target_ops
  53. {
  54.   char           *to_shortname;    /* Name this target type */
  55.   char           *to_longname;    /* Name for printing */
  56.   char            *to_doc;            /* Documentation.  Does not include trailing
  57.                    newline, and starts with a one-line descrip-
  58.                    tion (probably similar to to_longname). */
  59.   void           (*to_open) PARAMS ((char *, int));
  60.   void           (*to_close) PARAMS ((int));
  61.   void           (*to_attach) PARAMS ((char *, int));
  62.   void           (*to_detach) PARAMS ((char *, int));
  63.   void           (*to_resume) PARAMS ((int, int));
  64.   int            (*to_wait) PARAMS ((int *));
  65.   void           (*to_fetch_registers) PARAMS ((int));
  66.   void           (*to_store_registers) PARAMS ((int));
  67.   void           (*to_prepare_to_store) PARAMS ((void));
  68.   void           (*to_convert_to_virtual) PARAMS ((int, char *, char *));
  69.   void           (*to_convert_from_virtual) PARAMS ((int, char *, char *));
  70.   int            (*to_xfer_memory) PARAMS ((CORE_ADDR, char *, int, int,
  71.                      struct target_ops *));
  72.   void           (*to_files_info) PARAMS ((struct target_ops *));
  73.   int            (*to_insert_breakpoint) PARAMS ((CORE_ADDR, char *));
  74.   int           (*to_remove_breakpoint) PARAMS ((CORE_ADDR, char *));
  75.   void           (*to_terminal_init) PARAMS ((void));
  76.   void           (*to_terminal_inferior) PARAMS ((void));
  77.   void           (*to_terminal_ours_for_output) PARAMS ((void));
  78.   void           (*to_terminal_ours) PARAMS ((void));
  79.   void           (*to_terminal_info) PARAMS ((char *, int));
  80.   void           (*to_kill) PARAMS ((void));
  81.   void           (*to_load) PARAMS ((char *, int));
  82.   int           (*to_lookup_symbol) PARAMS ((char *, CORE_ADDR *));
  83.   void           (*to_create_inferior) PARAMS ((char *, char *, char **));
  84.   void           (*to_mourn_inferior) PARAMS ((void));
  85.   enum strata   to_stratum;
  86.   struct target_ops
  87.                *to_next;
  88.   int        to_has_all_memory;
  89.   int        to_has_memory;
  90.   int        to_has_stack;
  91.   int        to_has_registers;
  92.   int        to_has_execution;
  93.   struct section_table
  94.                *to_sections;
  95.   struct section_table
  96.            *to_sections_end;
  97.   int        to_magic;
  98.   /* Need sub-structure for target machine related rather than comm related? */
  99. };
  100.  
  101. /* Magic number for checking ops size.  If a struct doesn't end with this
  102.    number, somebody changed the declaration but didn't change all the
  103.    places that initialize one.  */
  104.  
  105. #define    OPS_MAGIC    3840
  106.  
  107. /* The ops structure for our "current" target process.  */
  108.  
  109. extern struct target_ops    *current_target;
  110.  
  111. /* Define easy words for doing these operations on our current target.  */
  112.  
  113. #define    target_shortname    (current_target->to_shortname)
  114. #define    target_longname        (current_target->to_longname)
  115.  
  116. /* The open routine takes the rest of the parameters from the command,
  117.    and (if successful) pushes a new target onto the stack.
  118.    Targets should supply this routine, if only to provide an error message.  */
  119. #define    target_open(name, from_tty)    \
  120.     (*current_target->to_open) (name, from_tty)
  121.  
  122. /* Does whatever cleanup is required for a target that we are no longer
  123.    going to be calling.  Argument says whether we are quitting gdb and
  124.    should not get hung in case of errors, or whether we want a clean
  125.    termination even if it takes a while.  This routine is automatically
  126.    always called just before a routine is popped off the target stack.
  127.    Closing file descriptors and freeing memory are typical things it should
  128.    do.  */
  129.  
  130. #define    target_close(quitting)    \
  131.     (*current_target->to_close) (quitting)
  132.  
  133. /* Attaches to a process on the target side.  */
  134.  
  135. #define    target_attach(args, from_tty)    \
  136.     (*current_target->to_attach) (args, from_tty)
  137.  
  138. /* Takes a program previously attached to and detaches it.
  139.    The program may resume execution (some targets do, some don't) and will
  140.    no longer stop on signals, etc.  We better not have left any breakpoints
  141.    in the program or it'll die when it hits one.  ARGS is arguments
  142.    typed by the user (e.g. a signal to send the process).  FROM_TTY
  143.    says whether to be verbose or not.  */
  144.  
  145. #define    target_detach(args, from_tty)        \
  146.     (*current_target->to_detach) (args, from_tty)
  147.  
  148. /* Resume execution of the target process.  STEP says whether to single-step
  149.    or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
  150.    to the target, or zero for no signal.  */
  151.  
  152. #define    target_resume(step, siggnal)    \
  153.     (*current_target->to_resume) (step, siggnal)
  154.  
  155. /* Wait for inferior process to do something.  Return pid of child,
  156.    or -1 in case of error; store status through argument pointer STATUS.  */
  157.  
  158. #define    target_wait(status)        \
  159.     (*current_target->to_wait) (status)
  160.  
  161. /* Fetch register REGNO, or all regs if regno == -1.  No result.  */
  162.  
  163. #define    target_fetch_registers(regno)    \
  164.     (*current_target->to_fetch_registers) (regno)
  165.  
  166. /* Store at least register REGNO, or all regs if REGNO == -1.
  167.    It can store as many registers as it wants to, so the entire registers
  168.    array must be valid.  Result is 0 for success, -1 for problems.  */
  169.  
  170. #define    target_store_registers(regs)    \
  171.     (*current_target->to_store_registers) (regs)
  172.  
  173. /* Get ready to modify the registers array.  On machines which store
  174.    individual registers, this doesn't need to do anything.  On machines
  175.    which store all the registers in one fell swoop, this makes sure
  176.    that REGISTERS contains all the registers from the program being
  177.    debugged.  */
  178.  
  179. #define    target_prepare_to_store()    \
  180.     (*current_target->to_prepare_to_store) ()
  181.  
  182. /* Convert data from raw format for register REGNUM
  183.    to virtual format for register REGNUM.  */
  184.  
  185. #define    target_convert_to_virtual(regnum, from, to)    \
  186.     (*current_target->to_convert_to_virtual) (regnum, from, to)
  187.     
  188. /* Convert data from virtual format for register REGNUM
  189.    to raw format for register REGNUM.  */
  190.  
  191. #define    target_convert_from_virtual(regnum, from, to)    \
  192.     (*current_target->to_convert_from_virtual) (regnum, from, to)
  193.  
  194. /* Reading and writing memory actually happens through a glue
  195.    function which iterates across the various targets.  Result is
  196.    0 for success, or an errno value.  */
  197.  
  198. extern int
  199. target_read_string PARAMS ((CORE_ADDR, char *, int));
  200.  
  201. extern int
  202. target_read_memory PARAMS ((CORE_ADDR, char *, int));
  203.  
  204. extern int
  205. target_write_memory PARAMS ((CORE_ADDR, char *, int));
  206.  
  207. extern int
  208. xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
  209.  
  210. extern int
  211. child_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
  212.  
  213. extern int
  214. target_xfer_memory PARAMS ((CORE_ADDR, char *, int, int));
  215.  
  216. /* From exec.c */
  217.  
  218. extern void
  219. print_section_info PARAMS ((struct target_ops *, bfd *));
  220.  
  221. /* Print a line about the current target.  */
  222.  
  223. #define    target_files_info()    \
  224.     (*current_target->to_files_info) (current_target)
  225.  
  226. /* Insert a breakpoint at address ADDR in the target machine.
  227.    SAVE is a pointer to memory allocated for saving the
  228.    target contents.  It is guaranteed by the caller to be long enough
  229.    to save "sizeof BREAKPOINT" bytes.  Result is 0 for success, or
  230.    an errno value.  */
  231.  
  232. #define    target_insert_breakpoint(addr, save)    \
  233.     (*current_target->to_insert_breakpoint) (addr, save)
  234.  
  235. /* Remove a breakpoint at address ADDR in the target machine.
  236.    SAVE is a pointer to the same save area 
  237.    that was previously passed to target_insert_breakpoint.  
  238.    Result is 0 for success, or an errno value.  */
  239.  
  240. #define    target_remove_breakpoint(addr, save)    \
  241.     (*current_target->to_remove_breakpoint) (addr, save)
  242.  
  243. /* Initialize the terminal settings we record for the inferior,
  244.    before we actually run the inferior.  */
  245.  
  246. #define target_terminal_init() \
  247.     (*current_target->to_terminal_init) ()
  248.     
  249. /* Put the inferior's terminal settings into effect.
  250.    This is preparation for starting or resuming the inferior.  */
  251.  
  252. #define target_terminal_inferior() \
  253.     (*current_target->to_terminal_inferior) ()
  254.  
  255. /* Put some of our terminal settings into effect,
  256.    enough to get proper results from our output,
  257.    but do not change into or out of RAW mode
  258.    so that no input is discarded.
  259.  
  260.    After doing this, either terminal_ours or terminal_inferior
  261.    should be called to get back to a normal state of affairs.  */
  262.  
  263. #define target_terminal_ours_for_output() \
  264.     (*current_target->to_terminal_ours_for_output) ()
  265.  
  266. /* Put our terminal settings into effect.
  267.    First record the inferior's terminal settings
  268.    so they can be restored properly later.  */
  269.  
  270. #define target_terminal_ours() \
  271.     (*current_target->to_terminal_ours) ()
  272.  
  273. /* Print useful information about our terminal status, if such a thing
  274.    exists.  */
  275.  
  276. #define target_terminal_info(arg, from_tty) \
  277.     (*current_target->to_terminal_info) (arg, from_tty)
  278.  
  279. /* Kill the inferior process.   Make it go away.  */
  280.  
  281. #define target_kill() \
  282.     (*current_target->to_kill) ()
  283.  
  284. /* Load an executable file into the target process.  This is expected to
  285.    not only bring new code into the target process, but also to update
  286.    GDB's symbol tables to match.  */
  287.  
  288. #define target_load(arg, from_tty) \
  289.     (*current_target->to_load) (arg, from_tty)
  290.  
  291. /* Look up a symbol in the target's symbol table.  NAME is the symbol
  292.    name.  ADDRP is a CORE_ADDR * pointing to where the value of the symbol
  293.    should be returned.  The result is 0 if successful, nonzero if the
  294.    symbol does not exist in the target environment.  This function should
  295.    not call error() if communication with the target is interrupted, since
  296.    it is called from symbol reading, but should return nonzero, possibly
  297.    doing a complain().  */
  298.  
  299. #define target_lookup_symbol(name, addrp)     \
  300.   (*current_target->to_lookup_symbol) (name, addrp)
  301.  
  302. /* Start an inferior process and set inferior_pid to its pid.
  303.    EXEC_FILE is the file to run.
  304.    ALLARGS is a string containing the arguments to the program.
  305.    ENV is the environment vector to pass.  Errors reported with error().
  306.    On VxWorks and various standalone systems, we ignore exec_file.  */
  307.  
  308. #define    target_create_inferior(exec_file, args, env)    \
  309.     (*current_target->to_create_inferior) (exec_file, args, env)
  310.  
  311. /* The inferior process has died.  Do what is right.  */
  312.  
  313. #define    target_mourn_inferior()    \
  314.     (*current_target->to_mourn_inferior) ()
  315.  
  316. /* Pointer to next target in the chain, e.g. a core file and an exec file.  */
  317.  
  318. #define    target_next \
  319.     (current_target->to_next)
  320.  
  321. /* Does the target include all of memory, or only part of it?  This
  322.    determines whether we look up the target chain for other parts of
  323.    memory if this target can't satisfy a request.  */
  324.  
  325. #define    target_has_all_memory    \
  326.     (current_target->to_has_all_memory)
  327.  
  328. /* Does the target include memory?  (Dummy targets don't.)  */
  329.  
  330. #define    target_has_memory    \
  331.     (current_target->to_has_memory)
  332.  
  333. /* Does the target have a stack?  (Exec files don't, VxWorks doesn't, until
  334.    we start a process.)  */
  335.    
  336. #define    target_has_stack    \
  337.     (current_target->to_has_stack)
  338.  
  339. /* Does the target have registers?  (Exec files don't.)  */
  340.  
  341. #define    target_has_registers    \
  342.     (current_target->to_has_registers)
  343.  
  344. /* Does the target have execution?  Can we make it jump (through hoops),
  345.    or pop its stack a few times?  */
  346.  
  347. #define    target_has_execution    \
  348.     (current_target->to_has_execution)
  349.  
  350. /* Routines for maintenance of the target structures...
  351.  
  352.    add_target:   Add a target to the list of all possible targets.
  353.  
  354.    push_target:  Make this target the top of the stack of currently used
  355.          targets, within its particular stratum of the stack.  Result
  356.          is 0 if now atop the stack, nonzero if not on top (maybe
  357.          should warn user).
  358.  
  359.    unpush_target: Remove this from the stack of currently used targets,
  360.          no matter where it is on the list.  Returns 0 if no
  361.          change, 1 if removed from stack.
  362.  
  363.    pop_target:     Remove the top thing on the stack of current targets.  */
  364.  
  365. extern void
  366. add_target PARAMS ((struct target_ops *));
  367.  
  368. extern int
  369. push_target PARAMS ((struct target_ops *));
  370.  
  371. extern int
  372. unpush_target PARAMS ((struct target_ops *));
  373.  
  374. extern void
  375. target_preopen PARAMS ((int));
  376.  
  377. extern void
  378. pop_target PARAMS ((void));
  379.  
  380. /* Struct section_table maps address ranges to file sections.  It is
  381.    mostly used with BFD files, but can be used without (e.g. for handling
  382.    raw disks, or files not in formats handled by BFD).  */
  383.  
  384. struct section_table {
  385.   CORE_ADDR addr;        /* Lowest address in section */
  386.   CORE_ADDR endaddr;        /* 1+highest address in section */
  387.   sec_ptr   sec_ptr;        /* BFD section pointer */
  388.   bfd       *bfd;        /* BFD file pointer */
  389. };
  390.  
  391. /* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR.
  392.    Returns 0 if OK, 1 on error.  */
  393.  
  394. extern int
  395. build_section_table PARAMS ((bfd *, struct section_table **,
  396.                  struct section_table **));
  397.  
  398. /* From inftarg.c */
  399.  
  400. extern void
  401. host_convert_from_virtual PARAMS ((int, char *, char *));
  402.  
  403. extern void
  404. host_convert_to_virtual PARAMS ((int, char *, char *));
  405.  
  406. /* From mem-break.c */
  407.  
  408. extern int
  409. memory_remove_breakpoint PARAMS ((CORE_ADDR, char *));
  410.  
  411. extern int
  412. memory_insert_breakpoint PARAMS ((CORE_ADDR, char *));
  413.  
  414. /* From target.c */
  415.  
  416. void
  417. noprocess PARAMS ((void));
  418.  
  419. #endif    /* !defined (TARGET_H) */
  420.